﻿using PMS.Data.Entities.Common;
using PMS.Services.EntityServices;

namespace PMS.Services.EventHandler.Caching
{
    /// <summary>
    /// Represents a generic attribute cache event consumer
    /// </summary>
    public partial class GenericAttributeCacheEventConsumer : CacheEventHandler<GenericAttribute>
    {
        /// <summary>
        /// 分别针对Insert/Update/Delete进行操作，
        /// 如果操作逻辑相同，可以调用 ClearCache(Setting entity)
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="entityEventType"></param>
        protected override void ClearCache(GenericAttribute entity, EntityEventType entityEventType)
        {
            ClearCache(entity);            
        }
        /// <summary>
        /// Clear cache data
        /// </summary>
        /// <param name="entity">Entity</param>
        protected override void ClearCache(GenericAttribute entity)
        {
            var cacheKey = _cacheKeyService.PrepareKey(CacheKeyConfigs.GenericAttributeCacheKey, entity.EntityId, entity.KeyGroup);
            Remove(cacheKey);
        }
    }

}
